Remove the update_remotes flag entirely
authorAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 20:54:24 +0000 (13:54 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 7 Aug 2014 00:09:24 +0000 (17:09 -0700)
This will inadvertently fix #337 as no lockfile will imply that all dependencies
are not precise, and will hence be fetched.

src/bin/cargo-generate-lockfile.rs
src/bin/cargo-git-checkout.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/sources/git/source.rs
src/cargo/util/config.rs
tests/test_cargo_compile_git_deps.rs

index d15cb22aaae193920efc152f251dbd6f85aeddaf..19304abc1abda00861f408c2ca3a7d4e45a5ca68 100644 (file)
@@ -34,6 +34,6 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     shell.set_verbose(options.flag_verbose);
     let root = try!(find_root_manifest_for_cwd(options.flag_manifest_path));
 
-    ops::generate_lockfile(&root, shell, true)
+    ops::generate_lockfile(&root, shell)
         .map(|_| None).map_err(|err| CliError::from_boxed(err, 101))
 }
index 8994e840b1d29196ff6dab1b61bbfbf989b3681a..14a58eda13a54c6a54d4fb8db9953ed7ee060460 100644 (file)
@@ -38,7 +38,7 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
 
     let source_id = SourceId::for_git(&url, reference.as_slice(), None);
 
-    let mut config = try!(Config::new(shell, true, None, None).map_err(|e| {
+    let mut config = try!(Config::new(shell, None, None).map_err(|e| {
         CliError::from_boxed(e, 1)
     }));
     let mut source = GitSource::new(&source_id, &mut config);
index c0effe7d215da8a9209f030dc60efd5814b5c807..5bb076a353dcaa26154b4093f7b5724d347eac52 100644 (file)
@@ -52,7 +52,7 @@ pub fn compile(manifest_path: &Path,
 
     log!(4, "compile; manifest-path={}", manifest_path.display());
 
-    if options.update {
+    if update {
         return Err(human("The -u flag has been deprecated, please use the \
                           `cargo update` command instead"));
     }
@@ -77,7 +77,7 @@ pub fn compile(manifest_path: &Path,
         let lockfile = manifest_path.dir_path().join("Cargo.lock");
         let source_id = package.get_package_id().get_source_id();
 
-        let mut config = try!(Config::new(*shell, update, jobs, target.clone()));
+        let mut config = try!(Config::new(*shell, jobs, target.clone()));
         let mut registry = PackageRegistry::new(&mut config);
 
         match try!(ops::load_lockfile(&lockfile, source_id)) {
@@ -117,7 +117,7 @@ pub fn compile(manifest_path: &Path,
 
     let ret = {
         let _p = profile::start("compiling");
-        let mut config = try!(Config::new(*shell, update, jobs, target));
+        let mut config = try!(Config::new(*shell, jobs, target));
         try!(scrape_target_config(&mut config, &user_configs));
 
         try!(ops::compile_targets(env.as_slice(), targets.as_slice(), &package,
index 2851da52f0255b67315662663e767a635d3b7fff..ced7788ee01d7e602eda32a3eee666c4fb274370 100644 (file)
@@ -15,8 +15,7 @@ use util::{CargoResult, human};
 use cargo_toml = util::toml;
 
 pub fn generate_lockfile(manifest_path: &Path,
-                         shell: &mut MultiShell,
-                         update: bool)
+                         shell: &mut MultiShell)
                          -> CargoResult<()> {
 
     log!(4, "compile; manifest-path={}", manifest_path.display());
@@ -31,7 +30,7 @@ pub fn generate_lockfile(manifest_path: &Path,
     let source_ids = package.get_source_ids();
 
     let resolve = {
-        let mut config = try!(Config::new(shell, update, None, None));
+        let mut config = try!(Config::new(shell, None, None));
 
         let mut registry = PackageRegistry::new(&mut config);
         try!(registry.add_sources(source_ids));
@@ -58,7 +57,7 @@ pub fn update_lockfile(manifest_path: &Path,
         None => return Err(human("A Cargo.lock must exist before it is updated"))
     };
 
-    let mut config = try!(Config::new(shell, true, None, None));
+    let mut config = try!(Config::new(shell, None, None));
     let mut registry = PackageRegistry::new(&mut config);
 
     let sources = match to_update {
index 743a2c3918fd577a122b47c7213b6b9d2f306d90..0fa87f2bb5bc7a3be70102052a7e777ea7b9ffd6 100644 (file)
@@ -159,7 +159,8 @@ impl<'a, 'b> Source for GitSource<'a, 'b> {
     fn update(&mut self) -> CargoResult<()> {
         let actual_rev = self.remote.rev_for(&self.db_path,
                                              self.reference.as_slice());
-        let should_update = self.config.update_remotes() || actual_rev.is_err();
+        let should_update = actual_rev.is_err() ||
+                            self.source_id.precise.is_none();
 
         let (repo, actual_rev) = if should_update {
             try!(self.config.shell().status("Updating",
index 4ed519ab1aa1d36e70949068246fd39efe233330..9878fe29e11709198e4c36da86418ee8797b389d 100644 (file)
@@ -9,7 +9,6 @@ use cargo_toml = util::toml;
 
 pub struct Config<'a> {
     home_path: Path,
-    update_remotes: bool,
     shell: &'a mut MultiShell,
     jobs: uint,
     target: Option<String>,
@@ -19,7 +18,6 @@ pub struct Config<'a> {
 
 impl<'a> Config<'a> {
     pub fn new<'a>(shell: &'a mut MultiShell,
-                   update_remotes: bool,
                    jobs: Option<uint>,
                    target: Option<String>) -> CargoResult<Config<'a>> {
         if jobs == Some(0) {
@@ -30,7 +28,6 @@ impl<'a> Config<'a> {
                 human("Cargo couldn't find your home directory. \
                       This probably means that $HOME was not set.")
             })),
-            update_remotes: update_remotes,
             shell: shell,
             jobs: jobs.unwrap_or(os::num_cpus()),
             target: target,
@@ -53,10 +50,6 @@ impl<'a> Config<'a> {
         &mut *self.shell
     }
 
-    pub fn update_remotes(&mut self) -> bool {
-        self.update_remotes
-    }
-
     pub fn jobs(&self) -> uint {
         self.jobs
     }
index 88c9ca6c25df96d078fb2a3bab5f6cb24016794a..ed7c38ef934b0dd610608e8b20a7e2f200fc3171 100644 (file)
@@ -665,7 +665,7 @@ test!(update_with_shared_deps {
                                             git_project.url())));
 
     // Make sure we still only compile one version of the git repo
-    assert_that(p.cargo_process("cargo-build"),
+    assert_that(p.process(cargo_dir().join("cargo-build")),
                 execs().with_stdout(format!("\
 {compiling} bar v0.5.0 ({git}#[..])
 {compiling} [..] v0.5.0 ({dir})
@@ -727,3 +727,69 @@ test!(dep_with_submodule {
                              COMPILING, root))
         .with_stderr(""));
 })
+
+test!(two_deps_only_update_one {
+    let project = project("foo");
+    let git1 = git_repo("dep1", |project| {
+        project
+            .file("Cargo.toml", r#"
+                [package]
+                name = "dep1"
+                version = "0.5.0"
+                authors = ["carlhuda@example.com"]
+            "#)
+            .file("src/lib.rs", "")
+    }).assert();
+    let git2 = git_repo("dep2", |project| {
+        project
+            .file("Cargo.toml", r#"
+                [package]
+                name = "dep2"
+                version = "0.5.0"
+                authors = ["carlhuda@example.com"]
+            "#)
+            .file("src/lib.rs", "")
+    }).assert();
+
+    let project = project
+        .file("Cargo.toml", format!(r#"
+            [project]
+
+            name = "foo"
+            version = "0.5.0"
+            authors = ["wycats@example.com"]
+
+            [dependencies.dep1]
+            git = '{}'
+            [dependencies.dep2]
+            git = '{}'
+        "#, git1.url(), git2.url()))
+        .file("src/main.rs", "fn main() {}");
+
+    assert_that(project.cargo_process("cargo-build"),
+        execs()
+        .with_stdout(format!("{} git repository `[..]`\n\
+                              {} git repository `[..]`\n\
+                              {} [..] v0.5.0 ([..])\n\
+                              {} [..] v0.5.0 ([..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING,
+                             UPDATING,
+                             COMPILING,
+                             COMPILING,
+                             COMPILING, project.url()))
+        .with_stderr(""));
+
+    File::create(&git1.root().join("src/lib.rs")).write_str(r#"
+        pub fn foo() {}
+    "#).assert();
+    git1.process("git").args(["add", "."]).exec_with_output().assert();
+    git1.process("git").args(["commit", "-m", "test"]).exec_with_output()
+        .assert();
+
+    assert_that(project.process(cargo_dir().join("cargo-update")).arg("dep1"),
+        execs()
+        .with_stdout(format!("{} git repository `{}`\n",
+                             UPDATING, git1.url()))
+        .with_stderr(""));
+})